﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace ProgramMain.Classifiers
{
    public partial class FrmCurveElementType : ProgramMain.Framework.frmBase
    {
        public FrmCurveElementType()
        {
            InitializeComponent();

            UniqueIdent = GenerateFormIdent();
        }

        private static string GenerateFormIdent()
        {
            return GenerateUniqueIdent(MethodInfo.GetCurrentMethod().DeclaringType.Name);
        }

        public static FrmCurveElementType ShowForm()
        {
            string FormIdent = GenerateFormIdent();
            FrmCurveElementType frm = (FrmCurveElementType)FindForm(FormIdent);
            if (frm != null)
            {
                frm.Activate();
            }
            else
            {
                frm = new FrmCurveElementType();
                frm.ShowAsMDI(Program.MainForm);
                //frm.RefreshForm();
            }
            return frm;
        }

        public void RefreshForm()
        {
            curveElementTypeList1.RefreshControl();
        }

        private void FrmCurveElementType_Load(object sender, EventArgs e)
        {
            try
            {
                this.curveElementKindsTableAdapter.SelectCommandTimeout = Properties.Settings.Default.LongQueryTimeout;
                this.curveElementKindsTableAdapter.Fill(this.simpleOpticNetDB.CurveElementKinds);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Непредвиденная ошибка во время чтения данных!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void lookupCurveElementKind_EditValueChanged(object sender, EventArgs e)
        {
            curveElementTypeList1.CurveElementKindID = (Nullable<int>)lookupCurveElementKind.EditValue;
        }
    }
}
